package com.powerunion.datacollection.dao.impl;

import org.apache.log4j.Logger;

import com.powerunion.datacollection.common.Constants;
import com.powerunion.datacollection.dao.DaoException;
import com.powerunion.datacollection.dao.TransmitTaskDao;
import com.powerunion.datacollection.model.TransmitTask;
import com.powerunion.datacollection.persistence.db.jdbc.operator.SqlParameter;
import com.powerunion.datacollection.persistence.db.jdbc.operator.SqlType;
import com.powerunion.datacollection.persistence.db.jdbc.operator.UpdateOperator;
import com.powerunion.util.log.LogHelper;

public class TransmitTaskDaoImpl extends JdbcBase implements TransmitTaskDao{
	// 初始化日志类
	private static final Logger logger = LogHelper.getInstance().getLogger(
			TransmitTaskDaoImpl.class);

	public boolean save(TransmitTask transmitTask)
			throws DaoException {

		StringBuffer sql = new StringBuffer();
		sql
				.append(
						"insert into dc_transmit_task(id,task_id,act_id,pro_id,task_type,transmit_date,transmit_user,receive_user)")
				.append(" values(?,?,?,?,?,sysdate,?,?)");

		UpdateOperator update = new UpdateOperator();
		update.setSql(sql.toString());

		String id = String.valueOf(this.getSeq("dc_transmit_task"));
		update.addParameter(new SqlParameter(SqlType.VARCHAR, id));
		update.addParameter(new SqlParameter(SqlType.VARCHAR, transmitTask
				.getTaskId()));
		update.addParameter(new SqlParameter(SqlType.VARCHAR, transmitTask
				.getActId()));
		update.addParameter(new SqlParameter(SqlType.VARCHAR, transmitTask
				.getProId()));
		update.addParameter(new SqlParameter(SqlType.INTEGER, new Integer(
				transmitTask.getTaskType())));
		update.addParameter(new SqlParameter(SqlType.VARCHAR, transmitTask
				.getTransmitUser()));
		update.addParameter(new SqlParameter(SqlType.VARCHAR, transmitTask
				.getReceiveUsers()));

		try {
			update.access();
		} catch (Exception e) {
			logger.error("", e);
			throw new DaoException("save throw error!");
		}

		int effectCount = update.getEffectCounts();
		if (effectCount > 0) {
			if (logger.isDebugEnabled()) {
				logger.debug("save:" + Constants.SAVE + "转发任务信息"
						+ Constants.SUCCESS);
			}
			return true;
		} else {
			if (logger.isDebugEnabled()) {
				logger.debug("save:" + Constants.SAVE + "转发任务信息"
						+ Constants.FAIL);
			}
			return false;
		}

	}

}
